/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.user;

import com.nus.constant.ConstantGender;
import com.nus.dataaccess.dao.base.BaseEntity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

/**
 *
 * @author robin.foe
 */

@SuppressWarnings("serial")
@DynamicUpdate
@DynamicInsert
@Entity
@Table(name="USER_INFO")
public class UserInfo extends BaseEntity{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}
    @Override
    public Serializable getPk() {return this.getId();}

    @Column(name="FULL_NAME")
    private String fullName;
    public String getFullName() {return fullName;}
    public void setFullName(String fullName) {this.fullName = fullName;}

    @Column(name="EMAIL")
    private String email;
    public String getEmail() {return email;}
    public void setEmail(String email) {this.email = email;}

    @Column(name="GENDER",length=1, columnDefinition="CHAR(1)")
    private String gender = ConstantGender.MALE;
    public String getGender() {return gender;}
    public void setGender(String gender) {this.gender = gender;}

    @Column(name="DOB")
    @Temporal(TemporalType.DATE)
    private Date dob;
    public Date getDob() {return dob;}
    public void setDob(Date dob) {this.dob = dob;}

    @Column(name="OFFICE_PHONE", length=30)
    private String officePhone;
    public String getOfficePhone() {return officePhone;}
    public void setOfficePhone(String officePhone) {this.officePhone = officePhone;}

    @Column(name="MOBILE_PHONE", length=30)
    private String mobilePhone;
    public String getMobilePhone() {return mobilePhone;}
    public void setMobilePhone(String mobilePhone) {this.mobilePhone = mobilePhone;}

    @Column(name="ACCOUNT_ID")
    private Long accountId;
    public Long getAccountId() {return accountId;}
    public void setAccountId(Long accountId) {this.accountId = accountId;}

    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="ACCOUNT_ID",referencedColumnName="ID",insertable=false,updatable=false)
    private UserAccount userAccount;
    public UserAccount getUserAccount() {return userAccount;}
    public void setUserAccount(UserAccount userAccount) {
	this.userAccount = userAccount;
	this.setAccountId((userAccount == null) ? null : userAccount.getId());
    }

    public UserInfo(){
        this.setUserAccount( new UserAccount() );
    }

}
